
package gblend.formatcovert;

/*
* Copyright 2010, Center for Advanced Information Systems, Nanyang Technological University
*
* File name: CtreetoStandard.java
*
* Abstract: Convert Ctree format to the standard format
*
* Current Version:      0.1
* Auther:               Jin Changjiu
* Modified Date:        June.3,2009
*
*/
/**
 *
 * @author cjjin
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Vector;
public class CtreetoStandard {

   
    public static void main (String[] args) throws FileNotFoundException
    {
         String filename = "0.05AIDS120k.fp.q";
         formatDotFile(filename);
    }


    public static void formatDotFile(String filename)
    {
	String output1="0.05AIDS40k";
        String strLine = null;
	FileOutputStream outStream1;
	PrintStream p;
        PrintStream q;
	FileInputStream inStream;
	DataInputStream in;
	BufferedReader br;

	File fin=new File(filename);
	File fout1=new File(output1);
       
	if(fin.exists())
	{
            try {

       		outStream1=new FileOutputStream(fout1,false);
                inStream=new FileInputStream(fin);
		// Connect print stream to the output stream
                p = new PrintStream( outStream1 );
               // Get the object of DataInputStream
                in = new DataInputStream(inStream);
                br = new BufferedReader(new InputStreamReader(in));
		//Read file line by line
    		try {

                      int vn = 0;
                      int en = 0;
                      int graphnum = -1;

                      Vector<String> nodelable = null;
                      Vector<String> edge = null;
                      while ((strLine = br.readLine()) != null)
                      {

                       // Print the content on the console
                          if(strLine.contains("#"))
                          {
                               graphnum++;
                               nodelable = new Vector<String>();
                               edge = new Vector<String>();
                               strLine = br.readLine();

                               vn = Integer.parseInt(strLine);
                               p.println("t # "+graphnum+" "+vn);
                               for(int i = 0;i<vn;i++)
                               {
                                    strLine = br.readLine();
                                    p.println("v "+i+" "+strLine);
                               }
                               strLine = br.readLine();
                               en = Integer.parseInt(strLine);
                               for(int i = 0;i<en;i++)
                               {
                                    strLine = br.readLine();
                                    p.println("e "+strLine+" 0");
                               }
                               p.println();
                           }
                          
                       }

                	//Close the input stream
                        in.close();
			p.close();
        	    }
		    catch (IOException e)
		    {
			// TODO Auto-generated catch block
			e.printStackTrace();
                    }
                    } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
			e.printStackTrace();
                    }
            }

	}


}
